<?php

namespace App\Http\Controllers\Backend;


use App\Http\Requests\Company\AccountRequest;
use App\Services\Company\Models\CompanyAccount;
use Illuminate\Http\Request;


class CountController extends BaseController
{




    public function index(Request $request)
    {


        $companyId =  $this->loginCompanyId();
        $accounts = CompanyAccount::query()->where('company_id',$companyId)->get()->toArray();
         return $this->successData(compact('accounts'));


    }

    public function store(AccountRequest $request, CompanyAccount $account)
    {

        $data = $request->filldata();
        $account->fill($data)->save();
        return $this->success("新建账户成功");
    }

    public function edit($id)
    {

        $account = CompanyAccount::query()->where('id',$id)->firstOrFail();
        return $this->successData(compact('account'));
    }

    public function update(AccountRequest $request,$id)
    {

        $data = $request->filldata();
        $company = CompanyAccount::query()->where('id',$id)->firstOrFail();
        $company->fill($data)->update();
        return $this->successData(__('账户更新成功'));
    }

    public function delete(Request $request, $id)
    {
        $account = CompanyAccount::query()->where('id', $id)->firstOrFail();
        $account->delete();
        return $this->success(__('删除账户成功'));
    }












}